var app = getApp(),
  $ = require("../../utils/httpHelper.js");
import tempObj from '../template/tempSelTime'
var address = require('../../utils/city.js')
const date = new Date()
Page({
  data: {
    username: '',
    phone: '',
    yzm: '',
    shenfencodestr: "",
    height: 0,
    shenfenjc: false,
    shenfencode: false,
    yzmjc: false,
    yzmstatus: false,
    showdialog:false,
    isedit:true,
    birthday:'',
    address:'',
    timePickerIsShow:false,
    timestr: '',
    year: '',
    month: "",
    day: "",
    //滑动框中放入的是第几个值
    value: [],
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this
    wx.getSystemInfo({
      success: function (res) {
        console.log(res);
        that.setData({ height: res.windowHeight })
      }
    })
    tempObj.init.apply(this, []);
    let par = {
      rd_session: app.globalData.userInfo.rd_session
    }
    $.httpPost("member_info", par, (data, err) => {
      if(data.data.data.name == null){
        this.setData({
          isedit:true
        })
        return
      }else{
        this.setData({
          username: data.data.data.name,
          shenfencodestr: data.data.data.idcard,
          phone: data.data.data.phone,
          address: data.data.data.address,
          value:data.data.data.birthday,
          timestr:data.data.data.birthday,
          isedit:false
        })
      }
      
    })

  },
  selectbirth(){
    if(this.data.isedit){
      this.setData({
        timePickerIsShow: true
      })
    }
    
  },
  timeChange(e){
    const val = e.detail.value
    this.setData({
      year: this.data.years[val[0]],
      month: this.data.months[val[1]],
      day: this.data.days[val[2]]
    })
  },
  formSubmit: function (e) {
    console.log('formmmmm')
    var rd_session = wx.getStorageSync('rd_session');
    let name = e.detail.value.username
    let phone = e.detail.value.phone
    let idcard = e.detail.value.shenfencodestr
    let address = e.detail.value.address
    console.log(name)
    if (this.checkinfo(name,phone,idcard)) {
      if (app.checkPhone(phone)){
        let par = {
          rd_session: rd_session,
          name: name,
          idcard: idcard,
          phone: phone,
          address: address,
          birthday: this.data.timestr
        }
        $.httpPost("edit_member_info", par, (data, err) => {
          if (data.result == "success") {
            wx.switchTab({
              url: '/pages/mine/mine',
            })
            this.setData({
              showdialog: false
            })
          }
        })
      }else{
        wx.showToast({
          title: '手机格式不对',
        })
      }
    } else {
      wx.showToast({
        title: '不能是空',
      })
    }
    console.log('form发生了submit事件，携带数据为：', e.detail.value)
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  checkinfo(name, phone, shenfencodestr) {
    console.log(name, phone, shenfencodestr)
    
    if (app.check_empty(name) || app.check_empty(phone) || app.check_empty(shenfencodestr)) {
      console.log(false)
      return false
    } else {
      console.log(true)
      return true
    }
  },
  toedit() {
    this.setData({
      isedit:true
    })
    
  },
 

})
